﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ciripescu_WebRole.Entities;
using Ciripescu_WebRole.BL;
namespace Ciripescu_WebRole
{
    public partial class cirip : BasePageAnonAndLoggedIn
    {
        string user;
        string id;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["userName"]!=null)
                user = Request.QueryString["userName"];
            else
                
                ShowError.ShowErrorMessage("Username invalid!", this);

            if (Request.QueryString["id"] != null)
                id = Request.QueryString["id"];
            else ShowError.ShowErrorMessage("Nu am gasit acel cirip!", this);

            UserManager um = new UserManager();
            CiripManager cm = new CiripManager();
            var u = um.GetItem(user);
            var cirip = cm.GetSingleCirip(user,id);

            if (u == null || cirip == null)
                ShowError.ShowErrorMessage("Nu am gasit acel cirip! Este posibil sa fi fost sters de catre autor!", this);

            imgPoza.ImageUrl = u.PictureUri;
            lblName.Text = u.FullName;
            lblContent.Text = cirip.Content;
            lblTimeAgo.Text = DisplayCirips.FormatCiripTime(cirip.TimePosted);

            string currentUser = "";
            if (Session["UserName"] != null) // ce rau imi pare acuma ca nu am pus o proprietate UserName in BasePage sa faca asta :(
                // m-am saturat deja de cate ori am scris codul asta
                // lenesul mai mult alearga
                currentUser = (string)Session["UserName"];

            if (user == currentUser)
                btnReply.Visible = false;
            else 
                btnReply.Visible = true;
            if (currentUser == "") // userul nu este logat
                btnReply.Visible = false;

        }
        public string GetUser()
        {
            return user;
        }

        protected void ReplyToCirip(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("/reply/" + user + "/" + id+"/");
        }
    }
}
